//
//  HLMainTabBar.m
//  weibo-OC
//
//  Created by 黄力 on 15/12/15.
//  Copyright © 2015年 HLTest. All rights reserved.
//

#import "HLMainTabBar.h"

@interface HLMainTabBar ()

@end

@implementation HLMainTabBar

- (instancetype)init
{
    self = [super init];
    if (self) {
        //添加一个中间的按钮
        [self addSubview:self.shareBtn];
    }
    return self;
}

//在该方法中修改子控件的frame
- (void)layoutSubviews {
    //必须实现父类方法
    [super layoutSubviews];
    //自定义按钮的尺寸
    CGFloat btnW = self.bounds.size.width / 5;
    CGFloat btnH = self.bounds.size.height;
    CGFloat btnY = 0;
    //索引
    NSInteger index = 0;
    //遍历子控件
    for (UIView *subview in self.subviews) {
        //判断当是系统类型的按钮
        if ([subview isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
            //获取x
            CGFloat btnX = btnW * index;
            //修改frame
            subview.frame = CGRectMake(btnX, btnY, btnW, btnH);
            //当索引为1时加2
            index += (index == 1 ? 2:1);
        }
        //判断当时自己添加的按钮时
        if ([subview isKindOfClass:[UIButton class]]) {
            //设置frame
            subview.frame = CGRectMake(btnW * 2, btnY, btnW, btnH);
            //该方法可以将控件移动的最上层
//            [subview bringSubviewToFront:<#(nonnull UIView *)#>]
        }
    }
}


//懒加载按钮
- (UIButton *)shareBtn {
    if (_shareBtn == nil) {
        _shareBtn = [[UIButton alloc] initWithImageName:@"tabbar_compose_icon_add" withBackImageName:@"tabbar_compose_button"];
    }
    return _shareBtn;
}

@end
